package edu.hendrix.grambler.grammars;

import edu.hendrix.grambler.Action;

public class ArithmeticWithActions extends  edu.hendrix.grambler.Grammar {
    public ArithmeticWithActions() {
        super();
        BinaryArithmeticAction power = new BinaryArithmeticAction("power", "expOp", "number");
        BinaryArithmeticAction product = new BinaryArithmeticAction("product", "mulOp", "power");
        BinaryArithmeticAction sum = new BinaryArithmeticAction("sum", "addOp", "product");
        
        addAction(new Action[] {sum}, 
        		addProduction("expr", new String[]{"sum", "sp"}));
        
        addAction(new Action[] {sum, sum},
        		addProduction("sum", new String[]{"sum", "sp", "addOp", "sp", "product"}, new String[]{"product"}));
        
        addAction(new Action[] {product, product},
        		addProduction("product", new String[]{"product", "sp", "mulOp", "sp", "power"}, new String[]{"power"}));
        
        addAction(new Action[] {power, power},
        		addProduction("power", new String[]{"power", "sp", "expOp", "sp", "number"}, new String[]{"number"}));
        addProduction("sp", new String[]{"\"\\s*\""});
        
        addAction(BinaryArithmeticAction.ArithmeticOperation.POWER, 
        		addProduction("expOp", new String[]{"'**'"}).get(0));
        
        addAction(new Action[] {BinaryArithmeticAction.ArithmeticOperation.MULTIPLICATION,
        		BinaryArithmeticAction.ArithmeticOperation.DIVISION}, 
        		addProduction("mulOp", new String[]{"'*'"}, new String[]{"'/'"}));
        
        addAction(new Action[] {BinaryArithmeticAction.ArithmeticOperation.ADDITION,
        		BinaryArithmeticAction.ArithmeticOperation.SUBTRACTION},
        		addProduction("addOp", new String[]{"'+'"}, new String[]{"'-'"}));
        
        addAction(new BinaryArithmeticAction.NumberAction(),
        		addProduction("number", new String[]{"\"\\d+\""}).get(0));
    }
}

